home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / PGM_TOOL / PREVIEW / ORGFILES / WSELPRN.PAS < prev   
Pascal/Delphi Source File  |  1995-11-12  |  4KB  |  169 lines

  1. unit wSelprn;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ExtCtrls, wPreview;
  8.  
  9. const
  10.  
  11.   DirectNote='Direct To My Printer';
  12.  
  13. type
  14.   Tnewprinter = class(TForm)
  15.     Button1: TButton;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     Label3: TLabel;
  19.     CheckBox1: TCheckBox;
  20.     prnlist: TComboBox;
  21.     qlist: TComboBox;
  22.     Label4: TLabel;
  23.     procedure Button1Click(Sender: TObject);
  24.     procedure FormCreate(Sender: TObject);
  25.     procedure prnlistClick(Sender: TObject);
  26.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  27.     procedure qlistClick(Sender: TObject);
  28.     procedure CheckBox1Click(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.     ActualPrnNum:array [0..MaxPrns-1] of integer;
  32.         procedure GetAvailQueues;
  33.         procedure SetupLists;
  34.   public
  35.     { Public declarations }
  36.   end;
  37.  
  38. var
  39.   newprinter: Tnewprinter;
  40.  
  41. implementation
  42.  
  43. {$R *.DFM}
  44.  
  45. uses dbfserver, CommonCode, wMainWin;
  46.  
  47. procedure Tnewprinter.Button1Click(Sender: TObject);
  48. begin
  49.   Close;
  50. end;
  51.  
  52. procedure Tnewprinter.GetAvailQueues;
  53. var ii,jj,kk:integer;
  54. begin
  55.   qlist.clear;
  56.   jj:=-1;
  57.   with lp do begin
  58.     if (CurDest>0) and (QueueCnt>0) and (lptprinters[CurDest].PrType>0) then begin
  59.       if (pin('LPT',upper(LptPrinters[CurDest].PrPort))) and
  60.          (procint(LptPrinters[CurDest].PrPort)=1) then
  61.         qlist.items.add(' '+DirectNote);
  62.       for ii:=1 to QueueCnt do begin
  63.         for kk:=1 to MaxQTypes do begin
  64.             if LptPrinters[CurDest].Prtype=QueueType[ii][kk] then begin
  65.                 qlist.items.add(' '+padr(QueueTitle[ii],25)+'  '+QueueName[ii]);
  66.           end;
  67.         end;
  68.       end;
  69.       for ii:=0 to qlist.items.count-1 do begin
  70.         if not empty(LptPrinters[CurDest].Queue) then begin
  71.           if pin(LptPrinters[CurDest].Queue,qlist.items[ii]) then begin
  72.             jj:=ii;
  73.           end;
  74.         end;
  75.       end;
  76.     end;
  77.   end;
  78.   if qlist.items.count>0 then begin
  79.     if jj>=0 then qlist.itemindex:=jj
  80.     else qlist.itemindex:=0;
  81.   end;
  82. end;
  83.  
  84. procedure Tnewprinter.SetupLists;
  85. var ii,jj,kk:integer;
  86.     tt,tt2:string;
  87. begin
  88.   kk:=lp.curdest;
  89.   prnlist.clear;
  90.   qlist.clear;
  91.   if lp.PrnCnt>0 then begin
  92.     for ii:=1 to lp.PrnCnt do begin
  93.       with lp.LptPrinters[ii] do begin
  94.         if CanSelect then begin
  95.          tt2:=' '+padr(Prname,22)+' '+padr(PrPort,5);
  96.          jj:=lp.GetQueueNum(queue);
  97.          if jj>0 then tt2:=tt2+'  '+lp.QueueTitle[jj]
  98.          else begin
  99.            if procint(PrPort)>0 then tt2:=tt2+'  '+DirectNote;
  100.          end;
  101.          prnlist.items.add(tt2);
  102.          ActualPrnNum[prnlist.items.count-1]:=ii;
  103.         end;
  104.       end;
  105.     end;
  106.   end;
  107.   jj:=-1;
  108.   for ii:=1 to prnlist.items.count do begin
  109.     if kk=ActualPrnNum[ii-1] then begin
  110.       jj:=ii-1;
  111.       break;
  112.     end;
  113.   end;
  114.   if jj>=0 then prnlist.itemindex:=jj;
  115.   GetAvailQueues;
  116. end;
  117.  
  118. procedure Tnewprinter.FormCreate(Sender: TObject);
  119. begin
  120.   top:=0;
  121.   left:=0;
  122.   width:=509;
  123.   height:=201;
  124.   centerhoriz(self);
  125.   Gen.AddWin('Select Printer',self);
  126.   SetupLists;
  127.   checkbox1.checked:=lp.WantsPreview;
  128.   show;
  129. end;
  130.  
  131. procedure Tnewprinter.prnlistClick(Sender: TObject);
  132. var ii,jj:integer;
  133. begin
  134.   lp.CurDest:=ActualPrnNum[prnlist.itemindex];
  135.   with lp.LptPrinters[lp.CurDest] do begin
  136.     lp.Capture(procint(PrPort),Queue);
  137.     JCmain.SetPreview;
  138.   end;
  139.   SetupLists;
  140. end;
  141.  
  142. procedure Tnewprinter.FormClose(Sender: TObject; var Action: TCloseAction);
  143. begin
  144.   lp.WantsPreview:=checkbox1.checked;
  145.   JCmain.SetPreview;
  146.   Gen.ReleaseWin(self);
  147.   action:=caFree;
  148. end;
  149.  
  150. procedure Tnewprinter.qlistClick(Sender: TObject);
  151. begin
  152.   with lp.LptPrinters[lp.CurDest] do begin
  153.     Queue:=iifs(pin('Direct',qlist.items[qlist.itemindex]),'',
  154.         ltrim(trim(copy(qlist.items[qlist.itemindex],29,20))));
  155.       { change queue capturing, if Queue empty, means end capture }
  156.       lp.Capture(procint(PrPort),Queue);
  157.     JCmain.SetPreview;
  158.   end;
  159.   SetupLists;
  160. end;
  161.  
  162. procedure Tnewprinter.CheckBox1Click(Sender: TObject);
  163. begin
  164.   lp.WantsPreview:=checkbox1.checked;
  165.   JCmain.SetPreview;
  166. end;
  167.  
  168. end.
  169.